﻿
var app = angular.module('WebApp', ['ngRoute']);
//var app = angular.module('WebApp', ['ngSanitize', 'ngRoute']);
app.directive('onErrorSrc', function () {
    return {
        link: function (scope, element, attrs) {
            element.bind('error', function () {
                if (attrs.src != attrs.onErrorSrc) {
                    attrs.$set('src', attrs.onErrorSrc);
                }
            });
        }
    }
});

app.controller("ChurchBoardController", function ($scope,$http) {
    url = "Home/GetChurchBoards";
    $http.get(url).success(function (responce) {
        $scope.boards = responce;
    });
});
app.controller("musicplayer", function ($scope) {
    
});
app.config(['$routeProvider',
function ($routeProvider) {
      $routeProvider.
        when('/FGPC', {
            templateUrl: 'Home/Home',
            controller: 'HomeController'
        }).
        when('/AboutFGPC', {
            templateUrl: 'Home/AboutUs',
            controller: 'AboutUsController'
        }).
          when('/HistoryOfFGPC', {
              templateUrl: 'Home/History',
              controller: 'HistoryController'
          })
          .
          when('/FromFgpcPresident', {
              templateUrl: 'Home/President',
              controller: 'PresidentController'
          })
          .
          when('/ContactUs', {
              templateUrl: 'Home/ContactUs',
              controller: 'ContactUsController'
          }).
          when('/LiveStreaming', {
              templateUrl: 'LiveStreaming',
              controller: 'LiveStreamingController'
          }).
          when('/Magazine', {
              templateUrl: 'Magazine',
              controller: 'MagazineController'
          }).
          when('/FGSS', {
              templateUrl: 'Miniteries/FGSS',
              controller: 'fgssController'
          }).
          when('/FGPCMission', {
              templateUrl: 'Home/Missionary',
              controller: 'MissionaryController'
          }).
          when('/MissionaryArticle/:ArticleId', {
              templateUrl: 'Home/MissionaryViews',
              controller: 'ArticleViewController'
          }).
          when('/JoinWithOurMinitry', {
              templateUrl: 'JoinWithOurMinitry/Index',
              controller: 'JoinWithOurMinitryController'
          }).
        otherwise({
            redirectTo: '/FGPC'
        });
  }]);
app.controller('JoinWithOurMinitryController', ['$scope', '$http', '$routeParams', function ($scope, $http) {
    $("#homebanner").hide();
    $scope.join = {};

    $scope.join.Gender = 1;

}])
app.controller('MissionaryController', ['$scope', '$http', '$routeParams', function ($scope, $http) {
    $("#homebanner").hide();

    var url;
    url = "Home/GetArticle";
    $http.get(url).success(function (responce) {
        $scope.Article = responce;
    });

}])
app.controller('ArticleViewController', ['$scope', '$http', '$routeParams', function ($scope, $http, $routeParams) {
    $("#homebanner").hide();
    
    var url;
    var Id = $routeParams.ArticleId;
    url = "Home/GetArticledetails";
    $http.get(url, { params: { dataId: Id } }).success(function (result) {
        $scope.Article = result;
        document.title ="FGPC | " + $scope.Article.ArticleName;
    });

    $scope.examples = [{
        "name": "<a href='http://www.google.ca'>Nexus S</a>",
        "snippet": "this one has an anchor tag"
    }, {
        "name": "<img src='http://www.w3schools.com/tags/smiley.gif' title='image tag example' />",
        "snippet": "this one has an image tag"
    }, {
        "name": "Just regular text",
        "snippet": "this is just plain ol' text"
    }];
}])
app.controller('fgssController', function ($scope) {
    $("#homebanner").hide();
});
app.controller('AboutUsController', function ($scope) {
    $("#homebanner").hide();
});

function callAtTimeout(sub) {
    //var popstatus = localStorage.getItem("PStatus");
    //if (popstatus == null || popstatus == "ASKL") {
    //    $("#myModal").modal({ backdrop: 'static' });
    //}
}
app.controller('HomeController', function ($scope) {
    alert();
    $("#homebanner").show();
    $("#myModal").modal({ backdrop: 'static' });
});
app.controller('HistoryController', function ($scope) {
    $("#homebanner").hide();
});
app.controller('PresidentController', function ($scope) {
    $("#homebanner").hide();
});
app.controller('ContactUsController', function ($scope, $http) {
    $("#homebanner").hide();

    initMap();


    
    var map;

    function initMap() {
        
        var uluru = { lat: 8.282885, lng: 77.299362 };
        map = new google.maps.Map(document.getElementById('map-canvas'), {
            zoom: 14,
            center: uluru
        });

        var contentString = '<div id="content">' +
            '<div id="siteNotice">' +
            '</div>' +
            '<h1 id="firstHeading" class="firstHeading">Uluru</h1>' +
            '<div id="bodyContent">' +
            '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
            'sandstone rock formation in the southern part of the ' +
            'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) ' +
            'south west of the nearest large town, Alice Springs; 450&#160;km ' +
            '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major ' +
            'features of the Uluru - Kata Tjuta National Park. Uluru is ' +
            'sacred to the Pitjantjatjara and Yankunytjatjara, the ' +
            'Aboriginal people of the area. It has many springs, waterholes, ' +
            'rock caves and ancient paintings. Uluru is listed as a World ' +
            'Heritage Site.</p>' +
            '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">' +
            'https://en.wikipedia.org/w/index.php?title=Uluru</a> ' +
            '(last visited June 22, 2009).</p>' +
            '</div>' +
            '</div>';

        var infowindow = new google.maps.InfoWindow({
            content: contentString
        });

        var marker = new google.maps.Marker({
            position: uluru,
            map: map,
            title: 'Uluru (Ayers Rock)'
        });
        marker.addListener('click', function () {
            infowindow.open(map, marker);
        });
    }


    google.maps.event.addListener(map, 'click', function (event) {

        

        console.log(event.latLng);
        

    });
    
    $scope.SaveDetails = function () {
        debugger;
        url = "Home/SaveMessages";
        $http.post(url, $scope.Message);
    }


});

app.controller('LiveStreamingController', function ($scope) {
    $("#homebanner").hide();
});